import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:wu_you/l10n/messages.dart';
import 'package:wu_you/model/user/user_model.dart';
import 'package:wu_you/res/colors.dart';
import 'package:wu_you/state/bloc/user_bloc.dart';
import 'package:wu_you/widgets/http_list_widget.dart';

///流水信息
class FundsListPage extends StatefulWidget{
  final String type;
  final String title;
  FundsListPage({Key key,this.type,this.title}):super(key: key);
  @override
  FundsListPageState createState() => FundsListPageState();
}
class FundsListPageState extends State<FundsListPage>{
  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    return Scaffold(
      appBar: AppBar(
        title: Text('${widget.title}'),
      ),
      body: HttpListWidget<FundsListModel, FundsListBloc>(
        creator: (context) => FundsListBloc(),
        onObtainData: (context, page) {
          BlocProvider.of<FundsListBloc>(context).add(FundsListEvent(widget.type,page));
        },
        successBuilder: (context, data) {
          return ListView.builder(
            itemCount: data.length,
            itemBuilder: (context, index) {
              FundsListModel item = data[index];
              return Container(
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius:
                  BorderRadius.all(Radius.circular(4)),
                ),
                margin: EdgeInsets.only(left: 8,right: 8,top: 5),
                child: ListTile(
                  title: Text("${item.notes}",
                      style: TextStyle(
                          fontSize: 16,
                          color: AppColors.textColor)),
                  subtitle: Text("${item.time}",
                      style: TextStyle(
                          fontSize: 12,
                          color: AppColors.textHintColor)),
                  trailing: Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Text(
                          "${item.amount}",
                          style: TextStyle(
                              fontSize: 14,
                              color: item.amount.startsWith("-") ? Colors.green : AppColors.primaryColor)),
                      Text("${message['text39']}:${item.balance}",style: TextStyle(color: AppColors.textHintColor,fontSize: 12),)
                    ],
                  )
                ),
              );
            },
          );
        }
      )
    );
  }

}